<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Common {

    public function createDropdown($array, $name, $selected, $ph='') {
      echo "<select id='{$name}' class='form-control' placeholder=\"{$ph}\" name=\"{$name}\">";
      foreach ($array as $key => $value) {
         // Test if `$selected == $value`
         if ($selected == $key) {
             $select = "selected='selected'";
         }
         else 
         	$select = "";
         echo "<option value=\"{$key}\"{$select}>{$value}</option>\n";
      }
      echo '</select>';
   }
   
   public function makeTextInputField($name, $value = '', $ph='') {
        echo "<input id='{$name}' class='form-control' type='text' name='{$name}' value='{$value}' placeholder='{$ph}' /> ";
    }
	
	public function unsetSessionData($name) {
		$this->session->unset_userdata($name);
	}
	
	public function dateformatsql($dateString) {
		$myDateTime = new DateTime($dateString);
		$newDateString = $myDateTime->format('Y-m-d');
		return $newDateString;
	}
	
	public function dateformatnormal($dateString) {
		$myDateTime = new DateTime($dateString);
		$newDateString = $myDateTime->format('d-m-Y');
		return $newDateString;
	}
	
	public function sendAck($emailid, $subject = '') {
		$emailTo = $emailid; 
		$body = "HI, Your mail has been sent. Please wait for the person to reply. Site Admin ";
		$headers = 'From: AITAA&reg <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . 'sudarshankushal@gmail.com';
		mail($emailTo, $subject, $body, $headers);
		$emailSent = true;
		
	}
	
	function generateRandomString() {
		$length = 8;
		$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
		$randomString = '';
		for ($i = 0; $i < $length; $i++) {
			$randomString .= $characters[rand(0, strlen($characters) - 1)];
		}
		return $randomString;
	}
}

/* End of file common.php */